<template>
  <view class="flex-col">

    <view class="bottom115">
      <view class="lineBottom10">
        <uni-section title="录入车辆年检信息" type="line"/>
      </view>

      <view style="margin-bottom: 20rpx" v-for="(item,index) in dataList" :key="index">
        <a-collapse ref="refACollapse">
          <template #title>
            <view style="display: flex;justify-content: space-between">
              <text style="margin-left: 30rpx">{{ item.vinNo || '' }}</text>
              <text>{{ item.carNo || '' }}</text>
            </view>
          </template>

          <template #content>
            <view class="flex-row align-stretch">
              <view class="flex-col flex1">
                <view class="text-line">
                  <text class="text-name">本次年检时间:</text>
                  <text class="text-value">
                    {{ item.inspectionTime|filterNull }}
                  </text>
                </view>
                <view class="text-line">
                  <text class="text-name">本次年检线上/线下:</text>
                  <text class="text-value">{{ handleLabel(dict.type.online_offline, item.onlineOffline) }}</text>
                </view>
                <view class="text-line">
                  <text class="text-name">预计下次年检期日:</text>
                  <text class="text-value">{{ item.inspectionNextTime|filterNull }}</text>
                </view>
                <view class="text-line">
                  <text class="text-name">预计下次年检线上/线下:</text>
                  <text class="text-value">{{ handleLabel(dict.type.online_offline, item.expireOnlineOffline) }}</text>
                </view>
                <view class="text-line">
                  <text class="text-name">年检费用:</text>
                  <text class="text-value">{{ item.inspectionPrice|filterNull }}</text>
                </view>
              </view>
            </view>

          </template>

          <template>
            <view>
              <inspection-info v-model="dataList[index]" :boole="true" :index="index" :ref="`refInspectionInfo${index}`"/>
            </view>

          </template>
        </a-collapse>
      </view>
    </view>

    <view class="button-container">
      <button class="btn-item" @click="submit">提 交</button>
    </view>
  </view>
</template>

<script>
import {feedbackList, addInspection} from "@/api/inspection";
import inspectionInfo from './components/inspectionInfo.vue'

export default {
  name: 'addBatch',
  dicts: ['online_offline'],
  components: {inspectionInfo},
  computed: {
    handleLabel() {
      return function (arr, type) {
        let name = "-";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },
  },
  watch: {},
  data() {
    return {
      boole: true,
      dataList: []
    };
  },
  onLoad(op) {
    let id = op.id.split(",");
    this.handleDetails(id);
  },
  mounted() {
  },
  methods: {
    async handleDetails(id) {
      try {
        let res = await feedbackList(id)
        this.dataList = res
      } catch (e) {
        console.error(e)
      }
    },

    async submit() {
      let effectPromises = []
      this.dataList.forEach((item, index) => {
        item.workOrderStatus = "2"
        let refs = `refInspectionInfo${index}`
        effectPromises.push(this.$refs[refs][0]?.handleEffect())
      })
      try {
        await Promise.all(effectPromises);
        uni.showLoading();
        const res = await addInspection(this.dataList);
        if (res.code === 200) {
          uni.$emit("refBackList", true);
          this.$modal.msgSuccess("提交成功");
          setTimeout(() => {
            this.$tab.navigateBack();
          }, 1000);
        }
      } catch (error) {
        if (typeof error.e === "string") {
          this.$nextTick(() => {
            uni.pageScrollTo({
              selector: error.e,
            });
          });
          this.$refs.refACollapse[error.i].changeStatus(true)
        }
      } finally {
        setTimeout(()=>{uni.hideLoading()},1000)
      }
    }
  },
};
</script>

<style scoped lang=""></style>


